package com.webvihar.access2db.adapters;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.webvihar.access2db.R;
import com.webvihar.access2db.activities.AddEditDeleteTableActivity;
import com.webvihar.access2db.activities.BaseActivity;
import com.webvihar.access2db.model.TableEntity;

public class TablesAdapter extends BaseA2DbAdapter{

	private Context mContext;
	private List<TableEntity> tableEntities;
	
	public TablesAdapter(Context context, List<TableEntity> tableEntities) {
		this.mContext = context;
		this.tableEntities = tableEntities;
	}

	@Override
	public int getCount() {
		return tableEntities.size();
	}

	@Override
	public Object getItem(int position) {
		return tableEntities.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		convertView = inflater.inflate(R.layout.tables_list_item, null);
		TextView tableName = (TextView)convertView.findViewById(R.id.table_name_txt);
		final TableEntity entity = (TableEntity)tableEntities.get(position);
		tableName.setText(entity.tableName);
		/*ImageView editTableBtn = (ImageView)convertView.findViewById(R.id.table_edit_btn);
		editTableBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v){
				Intent intent = new Intent(mContext, AddEditDeleteTableActivity.class);
				intent.putExtra(BaseActivity.KEY_TABLE_NAME, entity.tableName);
				intent.putExtra(BaseActivity.KEY_TABLE_MANAGEMENT_NAVIGATION_MODE, AddEditDeleteTableActivity.TABLE_MANAGEMENT_TYPE_EDIT);
				mContext.startActivity(intent);
			}
		});
		ImageView deleteTableBtn = (ImageView)convertView.findViewById(R.id.table_delete_btn);
		deleteTableBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v){
				Intent intent = new Intent(mContext, AddEditDeleteTableActivity.class);
				intent.putExtra(BaseActivity.KEY_TABLE_NAME, entity.tableName);
				intent.putExtra(BaseActivity.KEY_TABLE_MANAGEMENT_NAVIGATION_MODE, AddEditDeleteTableActivity.TABLE_MANAGEMENT_TYPE_DELETE);
				mContext.startActivity(intent);
			}
		}); */
		return convertView;
	}
}